
<!-- 设备总数、在线设备等数据卡片组 -->
 <template>
    <el-row :gutter="20">
        <el-col :span = "6">
            <el-card class = "stats-card" shadow="hover">
                <div class="card-content">
                    <div class = "card-title">设备总数</div>
                    <div class = "main-data">
                        <span class = "data-value"> {{ deviceStore.deviceTotal }}</span>
                        <div class = "growth-rate positive">
                            <el-icon class = "growth-icon"><CaretTop /></el-icon> 
                            <span class = "rate-text">+4.2%</span>
                        </div>
                    </div>
                </div>
            </el-card>
        </el-col>
        <el-col :span = "6">
            <!-- 在线设备卡片-->
            <el-card class = "stats-card" shadow="hover">
                <div class="card-content">
                    <div class = "card-title">在线设备</div>
                    <div class = "main-data">
                        <span class = "data-value"> {{ deviceStore.onlineDevices }}</span>
                        <div class = "online-rate">
                            <span class = "rate-text">92.1%在线率</span>
                        </div>
                    </div>
                </div>
            </el-card>
        </el-col>
        <el-col :span = "6">
            <!--故障设备卡片-->
            <el-card class = "stats-card" shadow="hover">
                <div class = "card-content">
                    <div class = "card-title">故障设备</div>
                    <div class="main-data">
                        <span class="data-value error">142</span>
                        <div class="status-badge warning">
                            <span class="status-text">未处理</span>
                        </div>
                    </div>
                </div>
            </el-card>
        </el-col>
        <el-col :span = "6">
            <!--今日告警卡片 -->
            <el-card class="stats-card" shadow="hover">
                <div class="card-content">
                    <div class="card-title">今日告警</div>
                    <div class="main-data">
                        <span class="data-value">38</span>
                        <div class="alert-info">
                            <span class="alert-new">12条新告警</span>
                        </div>
                    </div>
                </div>
            </el-card>
        </el-col>
    </el-row>
 </template>

<script setup>
import { CaretTop } from '@element-plus/icons-vue';
import { useDeviceStore } from '@/stores/deviceStore';
import { defineOptions } from 'vue';

defineOptions({
  name: 'DataCards'
});

// 组件逻辑
const deviceStore = useDeviceStore();
</script>



<style  scoped>
.stats-card {
  flex: 1;
  padding: 0;
  border-radius: 8px;
  border: none;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
}

.stats-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* 卡片内容 */
.card-content {
  margin: 0px;
  padding: 0px;
  height: 100%;
}

.card-title {
  color: #666;
  font-size: 18px;
  margin-bottom: 16px;
  font-weight: normal;
  line-height: 1.0;
  text-align: left;
}

.main-data {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* 主数字样式 */
.data-value {
  font-size: 26px;
  font-weight: bold;
  color: #000;
  line-height: 1.2;
}

.data-value.error {
  color: #ff4d4f; /* 故障设备红色数字 */
}

/* 增长率样式 - 蓝色 */
.growth-rate {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #1890ff;
  background: #f0f8ff;
}

.growth-icon {
  font-size: 12px;
  margin-right: 4px;
}

/* 在线率样式 - 绿色 */
.online-rate {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #52c41a;
  background: #f6ffed;
}

/* 状态徽章样式 - 红色圆点背景 */
.status-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  background: #ff4d4f;
}

.status-text {
  font-size: 12px;
}

/* 告警信息样式 */
.alert-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.alert-new {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
  line-height: 1.4;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .dashboard-cards {
    flex-wrap: wrap;
  }
  
  .stats-card {
    flex: 0 0 calc(50% - 10px);
  }
}

@media (max-width: 768px) {
  .stats-card {
    flex: 0 0 100%;
  }
  
  .data-value {
    font-size: 24px;
  }
  
  .card-content {
    padding: 16px;
  }
}

/* 确保所有卡片高度一致 */
.stats-card {
  min-height: 120px;
  display: flex;
  flex-direction: column;
}

.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.main-data {
  margin-top: auto;
}
</style>